/*
 * 菜单树的具体事件响应
 */
hjp.events.tree.MenuTreeEvents = function(node, event) {
	/*
	 * 处理奶粉的表格函数
	 */
	var milkgroupgrid_func = function() {
        // 定义数据源
        var store = new Ext.data.GroupingStore({
            autoLoad: true,
            reader: new Ext.data.JsonReader({
                fields: ['id', 'breed', 'brand', 'stage', 'wrap', 'state', 'price', 'discount', 'num'],
                root: 'rows',
                id: 'id'
            }),          
            proxy: new Ext.data.HttpProxy({      
                url: '/milks/all',
                method: 'GET'
            }),            
            sortInfo:{field: 'num', direction: "ASC"},
            groupField:'brand'
        });
        // 头描述
        var columns = [ 
            {header: "奶种", width: 50, sortable: true, dataIndex: 'breed', tooltip: '奶源的动物品种'},
            {header: "品牌", width: 80, sortable: true, dataIndex: 'brand', tooltip: '奶粉的品牌'},
            {header: "阶段", width: 150, sortable: true, dataIndex: 'stage', tooltip: '奶粉对于婴儿的年龄阶段'},
            {header: "包装", width: 80, sortable: true, dataIndex: 'wrap', tooltip: '奶粉的包装类型'},
            {header: "状态", width: 80, sortable: true, dataIndex: 'state', tooltip: '产品的当前状态'},
            {header: "当前成本", width: 60, sortable: true, renderer: Ext.util.Format.RMB, dataIndex: 'price', tooltip: '奶粉的实时的成本'},
            {header: "折扣", width: 50, sortable: true, renderer: Ext.util.Format.DISCOUNT, dataIndex: 'discount', tooltip: '奶粉的折扣律'},
            {header: "当前数量", width: 50, sortable: true, dataIndex: 'num', tooltip: '此奶粉在库存中剩余的重量'}
        ];		
		return new hjp.widgets.grid.MilkGroupGrid({
			title: '',
			store: store,
			columns: columns
		});
	};
	
	if (node.text == '奶粉' && node.parentNode.text == '库存数量') {
		__add_to_tabpanel(node, milkgroupgrid_func, '')
	}
}



// private
__add_to_tabpanel = function(node, grid_func, icon) {
	var center = hjp.home.Main.viewport.findById('centertabpanel');
	var tab = center.getItem(node.id);
    if(!tab) {
	   var tab = center.add({
		    id: node.id,
		    iconCls: icon,
		    xtype: "panel",
		    title: node.text + node.parentNode.text,
		    closable: true,
		    layout: "fit",
		    items: [grid_func()]
	    });
    }
    center.setActiveTab(tab);
}